package Filter;


import Utils.WebTool;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;

public class FurnManageFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        HttpSession session = httpServletRequest.getSession();

        if (session.getAttribute("login") == null){
            servletRequest.getRequestDispatcher("/Manage/manage_login.html").forward(servletRequest, servletResponse);
        }else {
           boolean b = (boolean) session.getAttribute("login");
           if (!b){
               servletRequest.getRequestDispatcher("/Manage/manage_login.html").forward(servletRequest, servletResponse);
           }else {
               filterChain.doFilter(servletRequest, servletResponse);
           }
        }

    }
    @Override
    public void destroy() {

    }
}
